/**
 * 
 */
package com.minyon_web_admin.common.exception;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

/** 
 * ClassName: CustomExceptionHandler <br/> 
 * Function: 实现HandlerExceptionResolver 接口自定义异常处理器  统一异常处理. <br/> 
 * Reason: TODO ADD REASON(可选). <br/> 
 * date: 2016年10月12日 下午11:17:13 <br/> 
 * 
 * @author wuwenya 
 * @version  
 * @since JDK 1.7 
 */
public class CustomExceptionHandler implements HandlerExceptionResolver {
	protected final Logger logger = (Logger) LoggerFactory
			.getLogger(getClass());// LoggerFactory.getLogger(LogbackConfigListener.class);

	/* (non-Javadoc)
	 * @see org.springframework.web.servlet.HandlerExceptionResolver#resolveException(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, java.lang.Exception)
	 */
	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		logger.error("统一异常处理,当前异常:"+ex.toString());
		Map<String, Object> model = new HashMap<String, Object>();  
        model.put("ex", ex);  
     // 根据不同错误转向不同页面  
       /* if(ex instanceof BusinessException) {  
            return new ModelAndView("error-business", model);  
        }else if(ex instanceof ParameterException) {  
            return new ModelAndView("error-parameter", model);  
        } else {  
            return new ModelAndView("error", model);  
        }  */
        return new ModelAndView("redirect:/error.shtml", model);
	}

}
